"""Top level user interface handling"""

import window
import pygame

class UI(object):
    """Creates the user interface for this game."""
    
    def __init__(self):
        pygame.init()
        self.window = window.Window()
        
        self._going = True
        self._e_handler = None
        
        
    def add_e_handler(self, handler):
        if self._e_handler:
            handler.set_sub_handler(self._e_handler)
        
        self._e_handler = handler
        
        
    def go(self):
        clock = pygame.time.Clock()
        while self._going:
            self.window.update()
            clock.tick(50)
       
            for event in pygame.event.get():
                if self._e_handler:
                    self._e_handler.handle_event(event)
                
            
        pygame.quit()
        
    
    def quit(self):
        self._going = False